#ifndef TASK_H
#define TASK_H

#include <map>
#include <vector>
#include "Location.h"
#include "macro.h"

#define ENUMERATE_OCCUPED (true)
#define ENUMERATE_FREE (false)


typedef std::pair<Ant,int> WeightTask;
typedef std::map<Task,WeightTask> TargetTask;
typedef std::vector<Location> LocationVector;

bool taskOccuped(const TargetTask& tasks, const Task& target, WeightTask& previousTask);
int distanceFast(const Location& from, const Location& to, const Location& resolution);

template <typename Validator>
// return true if target found
bool FindNearestTarget(const Location& source, const LocationVector& destinations, const Location& resolution, WeightTask& result, Validator validator)
{

//    OUT_PRINT_FUN "Source:" << source << " destinations_size " << destinations.size() << " resolution: " << resolution << std::endl;
    bool found = false;
    int dist_tmp , dist = resolution.row + resolution.col;

    FOR_EACH(dst,destinations)
    {
        dist_tmp = distanceFast(source, *dst, resolution);

        if ( dist > dist_tmp && true == (validator)(source,*dst))
        {
            found = true;
            dist = dist_tmp;
            result.first = *dst;
            result.second = dist;
        }
    }
    return found;
}

#endif // TASK_H
